package com.sojpt.boot.controller.business;

import com.jfinal.kit.Ret;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.SqlPara;
import com.sojpt.boot.ui.iview.IViewController;
import com.sojpt.kit.SoJLogKit;
import com.sojpt.model.DicPopedom;
import com.sojpt.model.LkyTableStorage;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/admin/teacherStudent/")
public class LkyTeacherFillState extends IViewController {
    /*
     * 成绩评定记录
     * */
    @GetMapping("list")
    public void list() {
        String uid=getPara("uid");
        String roid=Db.queryStr("SELECT `ROLE_ID` FROM `dic_user_role` WHERE `USER_ID`=?",uid);
        SqlPara sqlPara=null;
        Map<String,String> map =new HashMap<>();
        map.put("uid",getPara("uid"));
        map.put("tid",getPara("tid"));
        map.put("cid",getPara("cid"));
        map.put("mid",getPara("mid"));
        map.put("coid",getPara("coid"));
        map.put("dtmId",getPara("dtmId"));
        System.out.println("map***************"+map.entrySet());
        if (roid.equals("7371f2ced4154b8aaab16cccf378e7c3")) {     //老师权限
            sqlPara = Db.getSqlPara("lky_teacher_fill_state.select", map);;
        }else if(roid.equals("b40d665874274e399985083485a42785"))  {      //总管理
            sqlPara = Db.getSqlPara("lky_teacher_fill_state.selectAll", map);
        }
        
        Page<Record> page = Db.paginate(pageNumber(), pageSize(), sqlPara);
        renderJson(page);
    }
    @PostMapping("del")
    public void delByItsid(){
        DicPopedom dicPopedom = new DicPopedom();
        dicPopedom.setForwardAction("/admin/teacherStudent/del");
        String ltsId = getPara("ltsId");
        LkyTableStorage lkyTableStorage = new LkyTableStorage();
        lkyTableStorage.setId(ltsId);
        if (LkyTableStorage.dao.deleteById(ltsId)){
            renderJson(Ret.ok());
            dicPopedom.setPopedomName("删除成功");
        } else {
            renderJson(Ret.fail());
            dicPopedom.setPopedomName("删除失败");
        }
        SoJLogKit.writeLog(this, dicPopedom,getSessionUser());
    }
}
